﻿using System;
using System.Reflection;
namespace System.Data.Services
{
    /// <summary>
    /// Provides support for orchestrating error handling at different points in the processing cycle and for
    /// serializing structured errors.
    /// </summary>
    internal class ErrorHandler
    {
        /// <summary>Handles the specified <paramref name="exception" />.</summary>
        /// <param name="exception">Exception to handle</param>
        /// <remarks>The caller should re-throw the original exception if this method returns normally.</remarks>
        internal static void HandleTargetInvocationException(TargetInvocationException exception)
        {
            DataServiceException ex = exception.InnerException as DataServiceException;
            if (ex == null)
            {
                return;
            }
            throw new DataServiceException(ex.StatusCode, ex.ErrorCode, ex.Message, ex.MessageLanguage, exception);
        }
    }
}
